<?php
namespace app\common\controller\storage;

use Exception;

/**
 * 文件存储在本地服务器
 */
class LocalStorage extends Upload
{
    /**
     * 本地存储
     */
    public function upload($name)
    {
    	$file = $this->isUpload($name);
    	// 判断是否有文件上传
    	if ( ! $file instanceof \think\File ) return $file;
    	try {
    		$info = $file->move($this->localPath);
    		if ( $info ) {
    			$url = str_replace('\\', '/', module() . '/' . $info->getSaveName());
    		} else {
    			throw new Exception('上传失败');
    		}
    	} catch (Exception $e) {
    		return $this->fail($e->getMessage());
    	}
    	return $this->achieve(tomedia($url));
    }
}
